window.onload = function() {
	/*logo onblur事件*/
	function odj(oTxt) {
		var oTxt = document.getElementById("txt1")
		oTxt.onfocus = function() {
			if (oTxt.value == "多搜搜 ，意外惊喜等你拿") {
				oTxt.value = ""
				oTxt.style.color = "#ccc"
			}
		}
		oTxt.onblur = function() {
			if (oTxt.value == "") {
				oTxt.value = "多搜搜 ，意外惊喜等你拿"
				oTxt.style.color = "#ccc"
			}
		}
	}
	odj(txt1)

}

/*JQ b_login animate动画*/
function donghua() {
	$(function() {
		$(".login_l").animate({
			"width": "544px"
		}, 2000);
		$(".login_r").animate({
			"width": "544px"
		}, 2000);
	})
}
donghua()

/*登录判断*/
$(function() {
			$(":input[name='email']").focus(function() {
				$(".oeamil").html("请填写正确邮箱")
			})
			$(":input[name='email']").blur(function() {
					var email = $(this).val();
					var reg = /\w+[@]{1}\w+[.]\w+/;
					if (reg.test(email)) {
						$(".oeamil").html("填写正确")
					} else {
						$(".oeamil").html("请输入正确邮箱")
					}
				})
				/*密码*/
			$(":input[name='names']").blur(function() {
				var names = $(this).val();
				var reg = /^[A-Za-z_]\w{5,14}$/;
				if (reg.test(names)) {
					$(".oname").html("用户名可注册")
				} else {
					$(".oname").html("输入的用户名不正确")
				}
			})

			$(":input[name='passwords']").focus(function() {
				$(".opassword").html("6-16位字符")
			})
			$(":input[name='passwords']").blur(function() {
				var passwords = $(this).val();
				var reg = /^[0-9a-zA-Z_]{6,15}$/;
				if (reg.test(passwords)) {
					$(".opassword").html("密码正确")
				} else {
					$(".opassword").html("密码不合法，请验证")
				}
			})
			$(":input[name='psdname']").focus(function() {
				$(".opsd").html("两次输入密码必须一致")
			})
			$(":input[name='psdname']").blur(function() {
				var passwords = $(":input[name='passwords']").val();
				var psdname = $(this).val();
				if (psdname != passwords) {
					$(".opsd").html("两次密码不一致，请确认")
				} else {
					$(".opsd").html("密码一致")
				}
			})

			function Rand(min, max) {
				return parseInt(Math.random() * (max - min + 1) + min);
			}
				var yank = $(".yanks");
				var str = "";
				var index = -1;
				var count = 0;
				while (count < 4) {
					var index = Rand(48, 122);
					if ((index >= 65 && index <= 90) || (index >= 97 && index <= 122) || (index >= 48 && index <= 57)) {
						str += String.fromCharCode(index);
						count++;
					}
				}
				yank.html(str);

			$(".yanzheng").click(function() {
				var yank = $(".yanks");
				var str = "";
				var index = -1;
				var count = 0;
				while (count < 4) {
					var index = Rand(48, 122);
					if ((index >= 65 && index <= 90) || (index >= 97 && index <= 122) || (index >= 48 && index <= 57)) {
						str += String.fromCharCode(index);
						count++;
					}
				}
				yank.html(str);
			})

			$(".divzc").click(function() {
					var email = $(":input[name='email']").val();
					var names = $(":input[name='names']").val();
					var psd1 = $(":input[name='passwords']").val();
					var psd2 = $(":input[name='psdname']").val();
					var yzm = $(".yanks").val();
					var yzma=$(".yanzheng").val();
					if (email == "") {
						$(".zhuce").html("emaim不能为空");
					} else if (names == "") {
						$(".zhuce").html("账户名不能为空");
					} else if (psd1 == "") {
						$(".zhuce").html("密码名不能为空");
					} else if (psd2 == "") {
						$(".zhuce").html("二次密码不能为空");
					} else if (psd1 != psd2) {
						$(".zhuce").html("两次输入密码必须一致");
					} else {
						$(".zhuce").html("注册成功");
						//alert("1")
					}
           
           
					$.get("check.php?username=" + $(":input[name='names']").val(), function(res) {
						if (res == "true") {
							$(".oname").html("账户名已注册");
                            $(".zhuce").html("注册失败了");
						} else {
							$.get("charu.php?username=" + $(":input[name='names']").val() + "&psw=" + $(":input[name='passwords']").val(), function(response) {
								if (response == "ok") {
									$(".zhuce").html("注册成功了");
									
								} else {
									$(".zhuce").html("注册失败了");
								};
							});
						};
					});
				});
			
 				$(".divdl").on("click",function() {
					$.get("denglu.php?username=" + $(":input[name='dname']").val() + "&psw=" + $(":input[name='dpsd']").val(), function(res) {
						console.log($(":input[name='dname']").val());
						console.log($(":input[name='dpsd']").val());
	
						if (res == "登录成功") {
							//$(".dlzh").html("登录成功");
							alert("登陆成功！！！！");
							//window.location.href ="http://www.baidu.com";
							$(location).attr("href","http://localhost:8080/flydog/index.html");
						} else {
							//$(".dlzh").html("账户或密码错误");
							alert("账户或密码错误");
						};	
					});
                   
			    });
  

 });




